<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>于都县残疾人信息管理系统</title>
<link href="<%=basePath %>/assets/css/dpl-min.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath %>/assets/css/bui-min.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath %>/assets/css/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.form-horizontal .control-label{
width:150px;
}
</style>
</head>
<body style="padding-top:30px;margin: 0 auto;width: 1700px;">
	  <div class="main-con" id="maincon">
	     <div>
     	  <form id="searchForm" class="form-horizontal">
	        <div class="row">
	          <div class="control-group span8">
	            <label class="control-label">户主姓名：</label>
	            <div class="controls">
	              <input type="text" class="control-text" name="huzhuName" id="mhuzhuName">
	            </div>
	          </div>
	          <div class="control-group span8">
	            <label class="control-label">所属乡镇：</label>
	            <div class="controls">
	              <input type="text" class="control-text" name="town"  id="mtown">
	            </div>
	          </div>
	          <div class="control-group span8">
	            <label class="control-label">是否脱贫：</label>
	            <div class="controls" >
	              <select id="misOutPoor" name="isOutPoor" >
	                <option value="-1">全部</option>
	                <option value="0">否</option>
	                <option value="1">是</option>
	              </select>
	            </div>
	          </div>
	          <div class="control-group span12">
	            <label class="control-label">入档时间：</label>
	            <div class="controls">
	              <select id="maddTime" name="addTime" >
	                <option value="0">全部</option>
	                <option value="1">七天内</option>
	                <option value="2">一个月内</option>
	                <option value="3">近三个月</option>
	                <option value="4">本年度</option>
	              </select>
	            </div>
	          </div>
	          
	           
	        </div>
	        <div class="row">
	          <!-- <div class="control-group span12">
	            <label class="control-label">入档时间：</label>
	            <div class="controls">
	              <input type="text" class=" calendar" name="startDate"><span> - </span><input name="endDate" type="text" class=" calendar">
	            </div>
	          </div> -->
	          <div class="span3 offset16">
	            <button  type="button" id="btnSearch" class="button button-primary">搜索</button>
	          </div>
	        </div>
	      </form>
	     </div>
	    <!-- 表格开始  start-->
	    <div class="search-grid-container">
	      <div id="grid"></div>
	    </div>
	    <!-- 表格结束  end -->
    </div>


	<div class="demo-content">
		<!-- 初始隐藏 dialog内容 -->
		<div id="content" class="hide">
			<form class="form-horizontal"  method="post">
				<div class="row">
					<div class="control-group span16">
						<div class="controls">
							<input name="id" type="hidden" 
								class="input-normal control-text">
						</div>
					</div>
					<div class="control-group span16">
						<label class="control-label"><s>*</s>户主姓名：</label>
						<div class="controls">
							
							<input name="huzhuName" type="text" 
								class="input-normal control-text">
						</div>
					</div>
					<div class="control-group span16">
						<label class="control-label"><s>*</s>家庭人口：</label>
						<div class="controls">
							<input name="totalNum" type="text"
								data-rules="{required:true,number : true,allowDecimals : false;}"
								class="input-small control-text">
						</div>
						<label class="control-label"><s>*</s>残疾人口：</label>
						<div class="controls">
							<input name="disaNum" type="text"
								data-rules="{required:true,number : true,allowDecimals :false}"
								class="input-small control-text">
						</div>
					</div>
				</div>
				<div class="row">
					<div class="control-group span16">
						<label class="control-label"><s>*</s>贫困属性：</label>
						<div class="controls">
							<input name="poorShuxing" type="text" 
								class="input-normal control-text">
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="control-group span16">
						<label class="control-label"><s>*</s>主要致贫原因：</label>
						<div class="controls">
							<input name="poorCause" type="text" 
								class="input-large control-text">
						</div>
					</div>
				</div>
				<div class="row">
					<div class="control-group span8">
						<label class="control-label"><s>*</s>上年度人均纯收入：</label>
						<div class="controls">
							<input name="lastPerIncome" type="text"
								data-rules="{required:true,number : true}"
								class="input-small control-text">
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="control-group span8">
						<label class="control-label">是否脱贫：</label>
						<div class="controls">
							<p>
								<label><input id="isOutPoor1" name="isOutPoor" type="radio" value="0">否</label>
								<label><input id="isOutPoor2" name="isOutPoor" type="radio" value="1">是</label>
							</p>
						</div>
					</div>
				</div>
				
				<div style="display:none" data-depends="{'#isOutPoor2:checked':['show','enable'],'#isOutPoor2:unchecked':['hide','disable','clearErrors']}" class="bui-form-group">
					<div class="row">
						<div class="control-group span16 ">
							<label class="control-label"><s>*</s>脱贫时间：</label>
							<div id="range" class="controls">
								<input name="OutPoorDate" class="calendar" data-rules="{required:true}" type="text">
							</div>
						</div>
						<div class="control-group span12">
							<label class="control-label"><s>*</s>脱贫方式：</label>
							<div class="controls bui-form-field-select"  data-rules="{required:true}"
								data-select="{multipleSelect:true,items : [{text:'产业脱贫',value:'产业脱贫'},{text:'搬迁移民脱贫',value:'搬迁移民脱贫'},{text:'金融脱贫',value:'金融脱贫'},{text:'电商脱贫',value:'电商脱贫'},{text:'就业脱贫',value:'就业脱贫'},{text:'教育脱贫',value:'教育脱贫'},{text:'健康脱贫',value:'健康脱贫'},{text:'兜底保障脱贫',value:'兜底保障脱贫'}]}">
								<input type="hidden" name="OutPoorWay">
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="control-group span16">
						<label class="control-label">主要收入来源：</label>
						<div class="controls">
							<input name="mainIncome" type="text"
								class="input-large control-text">
						</div>
					</div>
				</div>
				<div class="row">
					<div class="control-group span16">
						<label class="control-label"><s>*</s>联系电话：</label>
						<div class="controls">
							<input name="contact" type="text"  
								class="input-large control-text">
							　
						</div>
					</div>
				</div>
				<div class="row">
					<div class="control-group span16">
						<label class="control-label"><s>*</s>家庭地址：</label>
						<div class="controls">
							于都县<input name="town" type="text" readonly="readonly"
								class="input-small control-text">
								<input name="vallige" type="text" 
								class="input-small control-text">
								<input name="team" type="text"
								class="input-small control-text">
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>

	<script type="text/javascript" src="assets/js/jquery-1.8.1.min.js"></script>
	<script type="text/javascript" src="assets/js/bui-min.js"></script>
	<script type="text/javascript" src="assets/js/sea.js"></script>
	<script type="text/javascript" src="assets/js/config-min.js"></script>
	<script type="text/javascript">
		BUI.use([ 'bui/grid', 'bui/data','common/search' ], function(Grid, Data,Search) {
			var Grid = Grid, Store = Data.Store, enumgenderObj = {
				1 : "是",
				0 : "否"
			}, columns = [ {
				title : '户主姓名',
				dataIndex : 'huzhuName',
				elCls : 'center',
				width : 80 
			}, {
				title : '家庭人口',
				dataIndex : 'totalNum',
				elCls : 'center',
				width : 50
			}, {
				title : '残疾人口',
				dataIndex : 'disaNum',
				elCls : 'center',
				width : 50
			}, {
				title : '贫困属性',
				dataIndex : 'poorShuxing',
				elCls : 'center',
				width : 100 
			},  {
				title : 'id',
				dataIndex : 'id',
				elCls : 'center',
				visible:false,
				width : 10 
			}, {
				title : '主要致贫原因',
				dataIndex : 'poorCause',
				elCls : 'center',
				width : 100 
			}, {
				title : '主要收入来源',
				dataIndex : 'mainIncome',
				elCls : 'center',
				width : 100
			}, {
				title : '上年度人均纯收入(元)',
				dataIndex : 'lastPerIncome',
				elCls : 'center',
				width : 60
			}, {
				title : '是否脱贫',
				dataIndex : 'isOutPoor',
				elCls : 'center',
				visible:false,
				width : 60,
				renderer : Grid.Format.multipleItemsRenderer(enumgenderObj)
			}, {
				title : '联系电话',
				dataIndex : 'contact',
				elCls : 'center',
				width : 60
			}, {
				title : '地址',
				dataIndex : 'dizhi',
				elCls : 'center',
				width : 150,
				renderer : function(v,obj){
					return '于都县'+obj.town+obj.vallige+obj.team;
				}
			}, {
				title : '操作',
				elCls : 'center',
				width : 50,
				renderer : function(v,obj) {
					return '<span class="grid-command btn-edit">编辑</span>&nbsp;|&nbsp;<span class="grid-command btn-view">查看</span>'
				}
			} ], data = [ {
				id:18,
				huzhuName : '肖喜燕'
			}, {
				huzhuName : '张三丰',
				isOutPoor : 1
			}, {
				isOutPoor : 1
			}, {
				huzhuName : '李俊基2',
				isOutPoor : 0,
				lastPerIncome : 23322,
				poorShuxing : '扶贫户'
			} ];
			  // 实例化 Grid.Plugins.Cascade 插件
	        var cascade = new Grid.Plugins.Cascade({
	  		    renderer : function(record){
	  		    	var outpoorflag = "	<span class='x-icon x-icon-small x-icon-error'><i class='icon icon-white icon-ban-circle'></i></span>未脱贫<br>";
	  		    	if(record.isOutPoor==1){
	  		    		outpoorflag = "<span class='x-icon x-icon-small x-icon-success'><i class='icon icon-ok icon-white'></i></span>已脱贫,脱贫时间：";
	  		    		outpoorflag += record.outPoorDate +"，脱贫方式："+ record.outPoorWay+"<br>";
	  		    	}
	  			    return '<div style="padding: 10px 20px;"><h2>详情信息</h2><p>' +outpoorflag+ '</p></div>';
	  		    }
	        });

			var isAddRemote = false, editing = new Grid.Plugins.DialogEditing({
				contentId : 'content', //设置隐藏的Dialog内容
				triggerCls : 'btn-edit', //触发显示Dialog的样式 
				//elStyle : {width:'100px', height:'200px'},
			 	/* proxy : {
	              method : 'POST' //更改为POST
	              //save : 'data/save.php' //会附加一个saveType 的参数，add,remove,update
	              //也可以使用一下方式：
	              //save : {
	              //  addUrl : 'data/add.php',
	              //  removeUrl : 'data/remove.php',
	              //  updateUrl : 'data/update.php'
	              //}
	            }, */
	            method : 'POST' ,
				editor : {
					title : '残疾人扶贫户建档立卡主要信息',
					width : 700,
					showMenu:true, 
					listeners:{
						show:function(){
							//console.log($('#content').css({'position':'absolute','top':'10px'}));
						}
					},
					success : function(){
						var edtor = this,
						form = edtor.get('form'),
						editType = editing.get('editType'),
						
						url='data/updatebaseinfo';
						//检验
		                form.valid();
						if(editType=='edit'){
							url='data/updatebaseinfo';
						}
						console.log(url+"--"+editType);
		                if(form.isValid()){
		                  form.ajaxSubmit({ //表单异步提交
		                    url : url,
		                    success : function(data){
		                       if(data.result==1){
			                         BUI.Message.Alert(data.msg,function(){
			                        	 if(editType=="add"){
				                        	 top.topManager.openPage({
							      				    id : 'detail',
							      				    href : "/admin/detail/"+data.obj,
							      				    title : '详情信息'
							      			  });
			                        	 }
			                        	 top.topManager.reloadPage();
			                         },'success');
		                    	  }else{
			                         BUI.Message.Alert(data.msg,function() {
			                             edtor.cancel();
			                             top.location.href = "/index.jsp";
			                             },'warning');
			                         
		                   	  }
		                      //将a 改成 1 测试一下显示错误
		                      if(data.hasError){ //返回的数据是 {hasError : fasle,error : 'xxxx',field : 'xxx'},也可以是任意格式的数据如 ： {success : false,'error' : 'xxxxx'}
		                        var field = data.field;
		                        form.getField(field).showErrors([data.error]); //也可以多个字段的错误信息 例如 errors : [{field : 'a',error: 'addd'},{field : 'a',error: 'addd'}]
		                      }else{
		                        edtor.accept();
		                        grid.render();
		                      }
	                    	  
		                      
		                      
		                    },
		                    error : function(){
		                      //do something
		                    	BUI.Message.Alert("系统出错，请稍后再试！",'warning');
		                    }
		                  });
		                }
					} 
				}
			}), store = Search.createStore('data/baseinfos',{
				//data : data,
            	autoLoad:true, //自动加载数据
            	params : { //配置初始请求的参数
             		huzhuName : $("input#mhuzhuName").val(),
             		town : $("input#mtown").val(),
             		isOutpoor : $("input#misOutPoor").val(),
             		addTime : $("input#maddTime").val()
            	},
				pageSize : 15,
				autoSync : true //保存数据后，自动更新
			}),gridCfg = Search.createGridCfg(columns,{
		        tbar : {
		            items : [
		              {text : '<i class="icon-plus"></i>新建',btnCls : 'button button-small btn-add',handler:addFunction},
		              {text : '<i class="icon-remove"></i>删除',btnCls : 'button button-small',handler : delFunction}
		            ]
		          },
		        height: 720,
	          	plugins : [editing,BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.AutoFit,Grid.Plugins.RowNumber,cascade], // 插件形式引入多选表格
	          	multipleSelect : false,
	          	forceFit : true,
	          	emptyDataTpl : '<div class="centered"><img alt="Crying" src="http://img03.taobaocdn.com/tps/i3/T1amCdXhXqXXXXXXXX-60-67.png"><h2>查询的数据不存在</h2></div>',
	          	// 底部工具栏
				bbar : {
					// pagingBar:表明包含分页栏
					pagingBar : true
				}
			});
			
			//grid.render();
			//添加最后一条记录，用于输入记录
	        //store.add({operation : true});
			var  search = new Search({
		        store : store,
		        gridCfg : gridCfg
	      	}),
	      	grid = search.get('grid');

			//添加记录
			function addFunction() {
				var newData = {
					isOutPoor : '1',
					huzhuName : '张世发',
					totalNum :'8',
					disaNum: '1',
					poorCause:'缺技能',
					lastPerIncome : 23322,
					poorShuxing : '扶贫户',
					mainIncome:'务农',
					town:'${sessionScope.user.town}',
					vallige:'黄麟村',
					contact:'15125623652',
					team:'中上组',
					id:0
				};
				
				store.addAt(newData, 15); //添加记录后，直接编辑
				editing.edit(newData, 'a'); //添加记录后，直接编辑
			}
			//删除选中的记录
			function delFunction() {
				var selections = grid.getSelection();
				var bids="";
				$.each(selections,function(k,v){
					if(this.id)
						bids +=(this.id+",");
				});
				console.log(bids);
				if(confirm("确定删除？")){
					$.ajax({
	                    url : 'data/deletebaseinfo/'+bids,
	                    type : 'post',
	                    cache : false,
	                    dataType : 'json',
	                    data : 1,
	                    success : function( data ){
	                        if ( data.result==1) {
	                            // 删除成功
	                            BUI.Message.Alert( data.msg,function(){
	                            	store.remove(selections);
	 	                            top.topManager.reloadPage();
	                            },'success' );
	                           
	                        } else {
	                            // 删除失败提示 - 改变提示样式
	                        	BUI.Message.Alert( data.msg, 'warning' );
	                        }
	                    } 
	                });
				}
				 
				
				
				
			}
			//清除点击链接的默认事件
	        grid.get('el').delegate('.grid-command','click',function(ev){
	          ev.preventDefault();
	        });
			grid.on('cellclick',function(ev){
				var target = ev.domTarget;
				if($(target).hasClass("btn-view")){
					//console.log(ev.record);
					//alert($(ev.row).find("input[name='id']").val()+55); 
					//alert(grid.getSelected());
					//取消当前行的选中状态
					grid.clearSelection();
					//return false;
					showData(ev.record);
				}
		    });
			/*  $("#btnSearch").on("click",function(){
				 console.log(grid);
				 grid.render();
			});   */
			function showData(obj){
				console.log(888888888);
				console.log(obj);
				var url = "/admin/detail/"+obj.id;
				 //打开相对地址，相对地址，必须以框架页面（main页面）为起始，不是相对于当前页面的位置
				top.topManager.openPage({
				    id : 'detail',
				    href : url,
				    title : '详情信息'
			    });
			}
			
			 
		});
		
		 
	</script>
	<!-- script end -->
</body>
</html>
